package com.itheima.goods.controller;


import com.itheima.goods.pojo.Goods;
import com.itheima.goods.service.GoodsService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {
   @Autowired
   private GoodsService goodsService;
    @GetMapping
    public Result findAll(){
        return goodsService.findAll();
    }
    @PostMapping
    public Result add(Goods goods){
        return goodsService.add(goods);
    }
    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page,
                           @PathVariable("size")Integer size){
        return goodsService.findPage(page,size);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return goodsService.findById(id);
    }
    @PutMapping("/{id}")
        public Result update(@PathVariable("id")Integer id,Goods goods){
        return goodsService.updateByid(id,goods);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id")Integer id){
        return goodsService.delete(id);
    }
}
